/*
 * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.semagia.atomico.server.dm.impl;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import com.semagia.atomico.dm.IAuthor;
import com.semagia.atomico.dm.IAuthorAwareEntity;
import com.semagia.atomico.dm.IEntity;
import com.semagia.atomico.dm.ISummaryAwareEntity;

/**
 * Abstract {@link IEntity} implementation.
 * 
 * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
 * @version $Rev: 117 $ - $Date: 2010-11-06 14:39:35 +0000 (Sat, 06 Nov 2010) $
 */
abstract class AbstractEntity implements IEntity, IAuthorAwareEntity, ISummaryAwareEntity {

    /**
     * The identifier (an IRI) of the entity.
     */
    protected final String _id;
    
    /**
     * The title.
     */
    protected final String _title;
    
    /**
     * Time when the entity was modified.
     */
    protected final long _updated;

    /**
     * Authors of this entity.
     */
    protected final Set<IAuthor> _authors;

    /**
     * Text summary.
     */
    protected String _summary;

    /**
     * Constructs a new instance.
     *
     * @param id The unique identifier of the entity, never <tt>null</tt>.
     * @param title The title of the entity, never <tt>null</tt>.
     * @param updated The modification time.
     */
    protected AbstractEntity(final String id, final String title, final long updated) {
        if (id == null) {
            throw new IllegalArgumentException("The id must not be null");
        }
        if (title == null) {
            throw new IllegalArgumentException("The title must not be null");
        }
        _id = id;
        _title = title;
        _updated = updated;
        _authors = new HashSet<IAuthor>();
    }

    /* (non-Javadoc)
     * @see com.semagia.atomico.dm.IEntity#getId()
     */
    @Override
    public String getId() {
        return _id;
    }

    /* (non-Javadoc)
     * @see com.semagia.atomico.dm.IEntity#getTitle()
     */
    @Override
    public String getTitle() {
        return _title;
    }

    /* (non-Javadoc)
     * @see com.semagia.atomico.dm.IEntity#getUpdated()
     */
    @Override
    public long getUpdated() {
        return _updated;
    }

    /* (non-Javadoc)
     * @see com.semagia.atomico.dm.IAuthorAwareEntity#getAuthors()
     */
    @Override
    public Set<IAuthor> getAuthors() {
        return Collections.unmodifiableSet(_authors);
    }

    /* (non-Javadoc)
     * @see com.semagia.atomico.dm.ISummaryAwareEntity#getSummary()
     */
    @Override
    public String getSummary() {
        return _summary;
    }

}
